#include "Square.h"
#include <GL/glew.h>
#include <iostream>

using namespace std;


/**
  Initialisation des buffers pour le carré
*/
void Square::initBuffer() {

  float vertex[]={-1,-1,0,-1,1,0,1,-1,0,1,1,0};
  float color[] = {255,0,0,255,255,0,0,255,255,0,0,255};
  glGenBuffers(1,&_bufferVertex);

  glBindBuffer(GL_ARRAY_BUFFER, _bufferVertex);
  glBufferData(GL_ARRAY_BUFFER,12*sizeof(float),vertex,GL_STATIC_DRAW);

  glGenBuffers(1,&_bufferColor);
  glBindBuffer(GL_ARRAY_BUFFER, _bufferColor);
  glBufferData(GL_ARRAY_BUFFER,12*sizeof(GLfloat),color,GL_STATIC_DRAW);


}

/**
  Tracé par buffer du carré
*/
void Square::drawBuffer() {

  glEnableClientState(GL_VERTEX_ARRAY);
  glBindBuffer(GL_ARRAY_BUFFER, _bufferVertex);
  glVertexPointer(3, GL_FLOAT, 0, 0);
 
  glEnableClientState(GL_COLOR_ARRAY);
  glBindBuffer(GL_ARRAY_BUFFER, _bufferColor);

  glColorPointer(3,GL_FLOAT,0,0);
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  glDisableClientState(GL_COLOR_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);

}


/** ************************************************************* */
/** ************************************************************* */
/** ************************************************************* */

Square::Square() {
  _bufferTexture.resize(3);
  _bufferTexCoord.resize(3);
}

Square::~Square(){
}

void Square::texture(unsigned int unite,GLuint id) {
  _bufferTexture[unite]=id;
}


